import { MessageBox } from 'element-ui';

/**
 * 提示确认框
 */
export default {
    confirm(option = {}) {
        option.title = option.title == null ? '提示' : option.title;
        option.msg = option.msg == null ? '此操作将永久删除该数据, 是否继续?' : option.msg;

        return new Promise((resolve, reject) => {
            if (option.alert) {
                MessageBox.alert(option.msg, option.title, {
                    dangerouslyUseHTMLString: true,
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    showCancelButton: option.cancel == true ? true : false,
                    type: 'warning'
                });
            } else {
                MessageBox.confirm(option.msg, option.title, {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    showCancelButton: option.cancel == true ? true : false,
                    type: 'warning'
                }).then(() => {
                    resolve(true);
                }).catch(() => {
                    resolve(false);
                });
            }

        });
    }
};
